<?php
ob_start();
 

define('prxy',"187.63.15.61:3128");

function video_indir($url){
	$useragent = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
	$referer = 'http://www.google.com';
	$ch = curl_init();
	curl_setopt ($ch, CURLOPT_URL, $url);
	curl_setopt ($ch, CURLOPT_HEADER, 0); 
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($ch, CURLOPT_REFERER, $referer);
	curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
	curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
	//curl_setopt ($ch, CURLOPT_HTTPPROXY, prxy);
	$rmx = curl_exec($ch);
	curl_close($ch);
	return $rmx;
}



$vid = $_GET['id'];
if(empty($vid)){die('Hata.');}
$filename = 'kaydets/flv-'.$vid.'.txt';
$ttt = 60 + substr($vid, 3, 2);
$zaman = 60 * 60; 
$new = 'no';
if (file_exists($filename)){
	if(time() - $zaman < filemtime($filename)) {
		$ac = fopen($filename,"r");
		$mp4 = fread($ac,filesize($filename));
		fclose($ac);
		$mp4 = trim($mp4);
		if($_GET['ec_seek'])$mp4 .= '&ec_seek='.$_GET['ec_seek'];
		header("Location: $mp4");
		die();
	}
	else {
		unlink($filename);
		$new = 'ok';
	}}else{$new = 'ok';}
if ($new == 'ok'){
$rand = rand(0,1000);
$md5 = md5($rand."75678366gjhsgdf73624hgdfsjhgsf63245sdkjfh");
$cekkod = video_indir("http://embed.redtube.com/video/info/?id=".$vid."&e=" .$rand. "&h=".$md5);
preg_match("#src=\"(.*?)\"#si", $cekkod, $aktar);
if(empty($aktar[1])){
	preg_match("#src='(.*?)'#si", $cekkod, $aktar);
}
$video = str_replace(array('FLV_H264_','FLV_'),array('http://videos.flv2.redtubefiles.com/_videos_t4vn23s9jc5498tgj49icfj4678','http://videos.mp4.redtubefiles.com/_videos_t4vn23s9jc5498tgj49icfj4678'),urldecode($aktar[1]));
if($aktar[1]){
	$fp = fopen($filename, 'w+');fwrite($fp,$video);fclose($fp);
}
if($_GET['ec_seek'])$video .= '&ec_seek='.$_GET['ec_seek'];
header("Location: $video");
}
?> 